home *** CD-ROM | disk | FTP | other *** search
- #include <Resources.h>
- #include <Icons.h>
- #include <OSUtils.h>
- #include <Sound.h>
- #include <Quickdraw.h>
- #include <QDOffscreen.h>
- #include <ControlDefinitions.h>
-
- enum
- {
- uppGetNextEventProcInfo = kPascalStackBased
- | RESULT_SIZE( SIZE_CODE( sizeof( Boolean ) ) )
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(EventRecord *)))
- };
-
- enum
- {
- uppFrontWindowProcInfo = kPascalStackBased
- | RESULT_SIZE( SIZE_CODE( sizeof( WindowPtr ) ) )
- };
-
- enum
- {
- uppButtonProcInfo = kPascalStackBased
- | RESULT_SIZE( SIZE_CODE( sizeof( Boolean ) ) )
- };
-
- #define kPauseLength 30
- #define kMovementWindow 2
-
- pascal Boolean NewGetNextEvent( short eventMask, EventRecord *theEvent );
- pascal WindowPtr NewFrontWindow( void );
- pascal Boolean NewButton( void );
- void ChangeWindow( WindowPtr theWindow, Boolean makeVisible );
- void MeasurePause( short coefficient );
-
- UniversalProcPtr gOldGetNextEvent = nil, gNewGetNextEvent;
- UniversalProcPtr gOldFrontWindow = nil, gNewFrontWindow;
- UniversalProcPtr gOldButton = nil, gNewButton;
- WindowPtr myFrontWindow = nil;
- Boolean selectWindow = true, lockButton = false, redrawWindow = false;
- Point mouseLoc;
- short theRatio = 1;
- long ticks = 0;
-
- void main(void)
- {
- OSErr err = noErr;
- THz oldZone;
-
- oldZone = GetZone();
- SetZone( SystemZone() );
-
- DetachResource(GetResource('INIT', 0));
-
- gOldGetNextEvent = GetToolTrapAddress( _GetNextEvent );
- gNewGetNextEvent = NewRoutineDescriptor( (ProcPtr)&NewGetNextEvent, uppGetNextEventProcInfo,kPowerPCISA);
- SetToolTrapAddress( gNewGetNextEvent, _GetNextEvent );
-
- gOldFrontWindow = GetToolTrapAddress( _FrontWindow );
- gNewFrontWindow = NewRoutineDescriptor( (ProcPtr)&NewFrontWindow, uppFrontWindowProcInfo,kPowerPCISA);
- SetToolTrapAddress( gNewFrontWindow, _FrontWindow );
-
- gOldButton = GetToolTrapAddress( _Button );
- gNewButton = NewRoutineDescriptor( (ProcPtr)&NewButton, uppButtonProcInfo, kPowerPCISA);
- SetToolTrapAddress( gNewButton, _Button );
-
- SetZone(oldZone);
- }
-
- pascal Boolean NewGetNextEvent( short eventMask, EventRecord *theEvent )
- {
- Boolean result;
- WindowPtr theWindow, realFrontWindow, cursorWindow;
- Point thePoint = theEvent->where;
- ControlHandle theControl;
- short thePart, controlPart;
-
- result = CallUniversalProc( gOldGetNextEvent, uppGetNextEventProcInfo, eventMask, theEvent );
-
- thePart = FindWindow( theEvent->where, &theWindow );
- cursorWindow = theWindow;
-
- realFrontWindow = (WindowPtr)CallUniversalProc( gOldFrontWindow, uppFrontWindowProcInfo );
-
- if ( theEvent->what == mouseDown )
- {
- if ( thePart == inContent || thePart == inDrag )
- {
- if ( GetWVariant( realFrontWindow ) != movableDBoxProc && GetWVariant( realFrontWindow ) != dBoxProc && GetWVariant( realFrontWindow ) != plainDBox )
- if ( theWindow != (WindowPtr)CallUniversalProc( gOldFrontWindow, uppFrontWindowProcInfo ) )
- if ( ( theEvent->modifiers & cmdKey ) == false )
- SelectWindow( theWindow );
- }
- }
-
- if ( GetWVariant( realFrontWindow ) == movableDBoxProc || GetWVariant( realFrontWindow ) == dBoxProc )
- return result;
- else if ( theWindow == nil && myFrontWindow != nil )
- {
- if ( myFrontWindow != nil )
- ChangeWindow( myFrontWindow, false );
-
- theWindow = (WindowPtr)CallUniversalProc( gOldFrontWindow, uppFrontWindowProcInfo );
-
- ChangeWindow( theWindow, true );
- myFrontWindow = nil;
- }
- else if ( theWindow != myFrontWindow )
- {
- if ( myFrontWindow != nil )
- ChangeWindow( myFrontWindow, false );
-
- ChangeWindow( theWindow, true );
- myFrontWindow = theWindow;
-
- theWindow = (WindowPtr)CallUniversalProc( gOldFrontWindow, uppFrontWindowProcInfo );
- if ( theWindow != myFrontWindow )
- ChangeWindow( theWindow, false );
- }
-
- SetPort( cursorWindow );
-
- GlobalToLocal( &thePoint );
- theControl = FindControlUnderMouse( thePoint, cursorWindow, &controlPart );
-
- if ( thePart == inDrag || thePart == inGrow || thePart == inMenuBar )
- MeasurePause( 1 );
- else if ( theControl && controlPart == kControlIndicatorPart )
- MeasurePause( 1 );
- else if ( theControl && controlPart == kControlButtonPart )
- {
- if ( ticks == 0 )
- ticks = TickCount();
-
- if ( TickCount() - ticks >= kPauseLength * 2 )
- {
- PostEvent( mouseDown, 0 );
- ticks = 0;
- }
-
- theRatio = 2;
- }
- else if ( thePart == inGoAway )
- {
- if ( ticks == 0 )
- ticks = TickCount();
-
- if ( TickCount() - ticks >= kPauseLength * 4 )
- {
- PostEvent( mouseDown, 0 );
- ticks = 0;
- }
-
- theRatio = 4;
- }
- else if ( thePart == inCollapseBox || thePart == inZoomIn || thePart == inZoomOut )
- {
- if ( ticks == 0 )
- ticks = TickCount();
-
- if ( TickCount() - ticks >= kPauseLength * 2 )
- {
- PostEvent( mouseDown, 0 );
- ticks = 0;
- }
-
- theRatio = 2;
- }
- else if ( ticks != 0 )
- ticks = 0;
-
- return result;
- }
-
- pascal WindowPtr NewFrontWindow( void )
- {
- WindowPtr theWindow;
-
- theWindow = (WindowPtr)CallUniversalProc( gOldFrontWindow, uppFrontWindowProcInfo );
-
- if ( GetWVariant( theWindow ) == movableDBoxProc || GetWVariant( theWindow ) == dBoxProc )
- return theWindow;
-
- if ( theWindow != myFrontWindow )
- return myFrontWindow;
- else
- return theWindow;
- }
-
- pascal Boolean NewButton( void )
- {
- Boolean button;
-
- if ( lockButton == true )
- {
- Point curMouse;
-
- if ( ticks == 0 )
- ticks = TickCount();
- else if ( TickCount() - ticks >= kPauseLength * theRatio )
- {
- lockButton = false;
- ticks = 0;
-
- return true;
- }
-
- GetMouse( &curMouse );
-
- if ( ( curMouse.h - mouseLoc.h ) > kMovementWindow || ( curMouse.h - mouseLoc.h ) < -kMovementWindow || ( curMouse.v - mouseLoc.v ) > kMovementWindow || ( curMouse.v - mouseLoc.v ) < -kMovementWindow )
- {
- ticks = TickCount();
- GetMouse( &mouseLoc );
- }
-
- return true;
- }
-
- button = (Boolean)CallUniversalProc( gOldButton, uppButtonProcInfo );
-
- return button;
- }
-
- void ChangeWindow( WindowPtr theWindow, Boolean makeVisible )
- {
- if ( selectWindow && makeVisible )
- SelectWindow( theWindow );
- else
- HiliteWindow( theWindow, makeVisible );
- }
-
- void MeasurePause( short coefficient )
- {
- if ( ticks == 0 )
- ticks = TickCount();
-
- if ( TickCount() - ticks >= kPauseLength * coefficient )
- {
- PostEvent( mouseDown, 0 );
- lockButton = true;
- GetMouse( &mouseLoc );
- ticks = 0;
- }
-
- theRatio = coefficient;
- }